import { BasicColumn, FormSchema } from "/@/components/Table"
import { rules } from "/@/utils/helper/validator"
import { listAccessKey } from "/@/views/system/accessKey/accessKey.api"
import { render } from "/@/utils/common/renderUtils"
import { PayCons } from "../PayCons"
import { useUserStore } from "/@/store/modules/user"

const userStore = useUserStore()

export const columns: BasicColumn[] = [
  {
    title: "应用AppId",
    width: 100,
    dataIndex: "id",
    customRender: ({ text }) => {
      return text
    },
  },
  {
    title: "应用名称",
    width: 100,
    dataIndex: "appName",
  },
  {
    title: "商户号",
    width: 100,
    dataIndex: "mchNo",
  },
  {
    title: "关联租户",
    width: 100,
    dataIndex: "bindTenant",
    customRender: ({ text }) => {
      return render.renderTag(text ? "是" : "否", text ? "green" : "purple")
    },
  },
  {
    dataIndex: "status",
    title: "状态",
    width: 60,
    customRender: ({ text }) => {
      let color = "green"
      if (text == "0") color = "red"
      if (text == "1") color = "green"

      return render.renderTag(render.renderDict(text, "mch_status"), color)
    },
  },
  {
    title: "创建时间",
    width: 150,
    dataIndex: "createdAt",
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "mchNo",
    label: "商户号",
    component: "Input",
    colProps: { span: 6 },
  },
  // {
  //   field: 'id',
  //   label: '应用AppId',
  //   component: 'Input',
  //   colProps: {span: 6},
  // },
  {
    field: "appName",
    label: "应用名称",
    component: "Input",
    colProps: { span: 6 },
  },

  {
    label: "状态",
    field: "status",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "mch_status",
      placeholder: "请选择状态",
    },
  },
]

export const formDetailSchema = [
  {
    field: "id",
    label: "应用AppId",
    with: 400,
  },
  {
    field: "appName",
    label: "应用名称",
  },
  {
    field: "mchNo",
    label: "商户号",
  },
  {
    field: "status",
    label: "状态",
    render: (curVal, data) => {
      let color = "green"
      if (curVal == "0") color = "red"
      if (curVal == "1") color = "green"

      return render.renderTag(render.renderDict(curVal, "mch_status"), color)
    },
  },
  // {
  //   field: 'accessKeyName',
  //   label: '访问密钥',
  //   render: (curVal, data) =>  {
  //     if (curVal) {
  //       return render.renderTag(curVal, 'green')
  //     }
  //     return render.renderTag('密钥不存在', 'red')
  //   },
  // },
  {
    field: "createdAt",
    label: "创建时间",
  },
  {
    field: "remark",
    label: "备注",
    labelMinWidth: 60,
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "应用AppId",
    required: true,
    component: "Input",
    ifShow: ({ values }) => {
      return values.id
    },
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
  },
  {
    field: "mchNo",
    label: "商户号",
    required: true,
    component: "Input",
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
  },

  {
    field: "appName",
    label: "应用名称",
    required: true,
    component: "Input",
  },
  {
    field: "isDefault",
    label: "默认",
    component: "RadioGroup",
    helpMessage: "当拉取收银台支付方式列表时, 若不传递appId, 就会获取默认的",
    defaultValue: false,
    componentProps: {
      options: [
        {
          label: "是",
          value: true,
        },
        {
          label: "否",
          value: false,
        },
      ],
    },
  },
  {
    field: "status",
    label: "状态",
    component: "JDictSelectTag",
    defaultValue: "1",
    componentProps: {
      dictType: "mch_status",
      type: "radio",
    },
  },
  // {
  //   field: 'accessKeyId',
  //   label: '访问密钥',
  //   slot: 'accessSecret',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     api: listAccessKey,
  //     showSearch: true,
  //     allowClear: true,
  //     labelField: 'name',
  //     valueField: 'id',
  //   },
  // },
  {
    field: "secretKey",
    label: "密钥key",
    ifShow: ({ values }) => values.id != "",
    helpMessage: "密钥key, 用于接口数据的加密或者一些接口的签名",
    component: "Input",
    componentProps: {
      readonly: true,
    },
  },
  {
    field: "platformPublicKey",
    label: "平台公钥",
    ifShow: ({ values }) => values.id != "",
    helpMessage: "支付平台公钥, 用于应用方进行回调/响应数据验签",
    component: "InputTextArea",
    componentProps: {
      readonly: true,
      autoSize: {
        minRows: 3,
        maxRows: 8,
      },
    },
  },
  {
    field: "appPublicKey",
    label: "应用公钥",
    ifShow: ({ values }) => values.id != "",
    helpMessage: "应用公钥, 用于应用方对请求数据签名",
    component: "InputTextArea",
    componentProps: {
      readonly: true,
      autoSize: {
        minRows: 2,
        maxRows: 8,
      },
    },
  },
  {
    field: "appPrivateKey",
    label: "应用私钥",
    ifShow: ({ values }) => values.id != "",
    helpMessage: "应用私钥, 用于支付平台对数据进行验签",
    component: "InputTextArea",
    componentProps: {
      readonly: true,
      autoSize: {
        minRows: 2,
        maxRows: 8,
      },
    },
  },
  {
    field: "remark",
    label: "备注",
    component: "InputTextArea",
    componentProps: {
      autoSize: {
        minRows: 2,
        maxRows: 8,
      },
    },
    colProps: {
      style: "color: red",
      sm: 24, // ≥576px
    },
  },
]
